import java.util.Stack;

class Solution {
    public boolean isValid(String s) {
        Stack<Character>st=new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char ch=s.charAt(i);
            if(ch=='['||ch=='{'||ch=='('){
                st.push(ch);
            }else{//此时开始判断右括号
                if(st.empty()){
                    return false;

                }
                char left=st.pop();
               if((left=='('&&ch!=')')||(left=='['&&ch!=']')||(left=='{'&&ch!='}')){
                   return false;
               }



            }


        }
        if(st.empty()){
            return  true;
        }
        return false;//遇到匹配问题都要想到用栈来解决
    }
}